/* GUI CONVERTED from reop14a.p (converter v1.76) Wed May 22 11:22:43 2002 */
/* reop14a.p - LABOR SCRAP TRANSACTION BY PART (REPETITIVE)                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.1.3 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 04/12/93   BY: emb *G760*                */
/* REVISION: 7.3      LAST MODIFIED: 02/14/96   BY: jym *G1N7*                */
/* REVISION: 7.3      LAST MODIFIED: 01/27/97   BY: *G2JV* Julie Milligan     */
/* REVISION: 8.5      LAST MODIFIED: 04/27/97   BY: *J1Q8* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *F230*                    */
/* $Revision: 1.5.1.3 $   BY: Jean Miller        DATE: 05/21/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define shared variable wr_recno as recid.
define shared variable wo_recno as recid.
define shared variable eff_date as date.
define shared variable site like rps_site no-undo.
define shared variable prline like rps_line no-undo.
define shared variable part like op_part no-undo.
define shared variable op like ps_op no-undo.
define shared variable bom_code as character format "x(18)".
define shared variable routing as character format "x(18)".
define shared variable schedule_id like wo_lot.
define shared variable undo-all like mfc_logical no-undo.
define shared variable mod_issrc like mfc_logical.
define shared variable qty like op_qty_comp.

define variable last_date like op_date.
define variable rsn_desc1 like rsn_desc.
define variable shift like op_shift.
define variable ro_recid as recid.
define variable ptstatus like pt_status.

define variable msg-type as integer.
define variable conv like um_conv.
define variable um like pt_um.
define variable tot_units like op_qty_comp.
define variable disp_units as character format "x(15)".
define variable ok like mfc_logical no-undo.
define variable prompt-routing like mfc_logical no-undo.

define shared frame a.

{reopf14a.i} /* Form definition */

mainloop:
do with frame a on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


   undo-all = yes.
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      update
         routing
         bom_code
      with frame a
      editing:

         if frame-field = "routing" then do:

            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i ptr_det ptr_part
               "ptr_part = part and ptr_site = site"
               ptr_routing "input routing"}

            if recno <> ? then do:
               display ptr_routing @ routing.
               recno = ?.
            end.
         end.

         else
         if frame-field = "bom_code" then do:

            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i ptr_det ptr_part
               "ptr_part = part
                 and ptr_site = site
                 and ptr_routing = input routing"
               ptr_bom_code "input bom_code"}

            if recno <> ? then do:
               display ptr_bom_code @ bom_code.
               recno = ?.
            end.

         end.

         else do:
            readkey.
            apply lastkey.
         end.

      end.

      /* Validate Work Order Routing and BOM Codes */
      {gprun.i ""wortbmv.p""
         "(input part,
           input site,
           input routing,
           input bom_code,
           input 3,
           output ok,
           output prompt-routing)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if not ok then do:
         if prompt-routing then
            next-prompt routing.
         else next-prompt bom_code.
         undo,retry.
      end.

      if routing = "" and
         not can-find (first ro_det where ro_routing = part)
      then do:
         next-prompt routing.
         /* ROUTING DOES NOT EXISTS */
         {pxmsg.i &MSGNUM=126 &ERRORLEVEL=3}
         undo, retry.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* mainloop */

   find pt_mstr no-lock where pt_part = part no-error.
   find ptp_det no-lock where ptp_part = part
                          and ptp_site = site no-error.

   if schedule_id <> "" then do:

      find wo_mstr no-lock where wo_lot = schedule_id no-error.

      schedule_id = "".

      if available wo_mstr
         and (wo_bom_code = bom_code
          or (wo_bom_code = wo_part and bom_code = "")
          or (wo_bom_code = "" and bom_code = wo_part))
         and (wo_routing = routing
          or (wo_routing = wo_part and routing = "")
          or (wo_routing = "" and routing = wo_part))
      then
         schedule_id = wo_lot.
   end.

   find first wo_mstr
      where wo_type = "C"
        and wo_part = input op_part
        and wo_site = site
        and wo_line = prline
        and (wo_routing = routing or (wo_routing = part and routing = ""))
        and (wo_bom_code = bom_code or (wo_bom_code = part and bom_code = ""))
   no-lock no-error.

   repeat:

      if not available wo_mstr then leave.
      if wo_status <> "C" then leave.

      find next wo_mstr
         where wo_type = "C"
           and wo_part = input op_part
           and wo_site = site
           and wo_line = prline
           and (wo_routing = routing or (wo_routing = part and routing = ""))
           and (wo_bom_code = bom_code or (wo_bom_code = part and bom_code = ""))
      no-lock no-error.

   end.

   /*VALIDATE THE OPERATION */
   last_date = today.

   {reopval.i
      &part = part
      &routing = routing
      &op = op
      &date = last_date
      &prompt = op_wo_op
      &frame = "a"
      &leave = ""yes""
      &loop = "mainloop"}

   if not available wo_mstr then do:

      ptstatus = pt_status.
      substring(ptstatus,9,1) = "#".

      if can-find(isd_det where isd_status = ptstatus
                            and isd_tr_type = "ADD-RE")
      then do:
         /* Restricted Procedure for item status code # */
         {pxmsg.i &MSGNUM=358 &ERRORLEVEL=3 &MSGARG1=pt_status}
         undo mainloop, leave mainloop.
      end.

      {gprun.i ""rewocr.p"" "(part,last_date)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      find wo_mstr no-lock where recid(wo_mstr) = wo_recno.

   end.

   do transaction:

      find wr_route where wr_lot = wo_lot
                      and wr_op = input op_wo_op
      no-lock no-error.

      if not available wr_route then do:
         /* CREATE wr_route from ro_det for part and operation */
         create wr_route.
         assign
            wr_nbr = wo_nbr
            wr_lot = wo_lot
            wr_part = input op_part
            wr_op = input op_wo_op
            wr_start = today
            wr_due = today
            wr_qty_ord = 0
            wr_desc = ro_desc
            wr_wkctr = ro_wkctr
            wr_mch = ro_mch
            wr_mch_op = ro_mch_op
            wr_milestone = ro_milestone
            wr_setup = ro_setup
            wr_run = ro_run
            wr_move = ro_move
            wr_tool = ro_tool
            wr_vend = ro_vend.
      end.

   end.

   wo_recno = recid(wo_mstr).
   wr_recno = recid(wr_route).
   undo-all = no.

end.
/*GUI*/ if global-beam-me-up then undo, leave.

